<template>
  <div :style="newStyle">
    <span v-if="$attrs.onlyShow">{{getOptionsText(modelValue,resData,props)}}</span>
    <el-radio-group v-else v-model="formValue" v-bind="$attrs" @change="onChange">
      <template v-if="$attrs.__config__.optionType=='button'">
        <el-radio-button
          v-for="item in resData"
          :key="item[props.value]"
          :label="item[props.value]"
          :value="item[props.value]"
          :border="$attrs.__config__.border"
        >{{ item[props.value] }}</el-radio-button>
      </template>
      <template v-else>
        <el-radio
          v-for="item in resData"
          :key="item[props.value]"
          :label="item[props.value]"
          :value="item[props.value]"
          :border="$attrs.__config__.border"
        >{{ item[props.label] }}</el-radio>
      </template>
    </el-radio-group>
  </div>
</template>

<script>
import { getOptionsText } from "../../../utils";

import { comMixin } from "../../../utils/comMixins";
export default {
  mixins: [comMixin],
  name: "form-radio-group",
  model: {
    prop: "value", // 绑定的值，通过父组件传递
    event: "update",
  },
  props: {
    modelValue: {
      type: [String, Number],
      default: "",
    },
  },
  computed: {
    formValue: {
      get() {
        return this.modelValue;
      },
      set(val) {
        this.$emit("update:modelValue", val);
      },
    },
  },
  methods: { getOptionsText },
};
</script>

<style lang="scss" scoped>
</style>